﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using DH.Share.Comm.customerclass;
using DH.Share.Comm.DataHelp;
namespace DH.Share.Comm.Commands
{
    public class LoginDataSource
    {
        public LinkSource linkSource { get; set; }
        public static string ErrorInfo { get; private set; }
        public bool ToLogin(UserTable usertable, bool auth)
        {
            if (auth == false || usertable == null || linkSource!=null)
            {
                ErrorInfo = ErrorInfo ?? "连接参数为空或其它验证条件不符";
                return false;
            }
            else
            {
                string name = usertable.Name;
                string pwd = usertable.Pwd;
        
                if (linkSource.DataHelps.RetuLinkSqlBool())
                {
                    string commandtxt = $"select * from {nameof(UserTable).TbFullName()} where user_loginname ='{name}' and user_pwd='{pwd.EncryptAes()}'";
                    if (linkSource.DataHelps.GetSelect(commandtxt).Result)
                    {
                        return true;
                    }
                    else
                    {
                        ErrorInfo = ErrorInfo ?? "用户名称或密码错误";
                        return false;
                    }
                }
                else
                {
                    ErrorInfo = ErrorInfo ?? "数据源链接错误";
                    return false;
                }
            }
        }
    }
}
